home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group03a.txt
/
000073_icon-group-sender_Tue Apr 15 12:26:43 2003.msg
< prev
next >
Wrap
Internet Message Format
|
2003-12-22
|
2KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id h3FJQgU11987
for icon-group-addresses; Tue, 15 Apr 2003 12:26:42 -0700 (MST)
Message-Id: <200304151926.h3FJQgU11987@baskerville.CS.Arizona.EDU>
From: Richard Bos <rlb@hoekstra-uitgeverij.nl>
X-Newsgroups: comp.lang.icon
Mail-Copies-To: nobody
Subject: Re: Simplifying Integer Arithmetic
User-Agent: MT-NewsWatcher/3.1 (PPC)
Date: Tue, 15 Apr 2003 17:37:33 +0200
X-Complaints-To: abuse@nl.uu.net
To: icon-group@cs.arizona.edu
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
In article <JoVma.17461$Gb1.15725@nwrdny01.gnilink.net>,
"Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net> wrote:
> Within the file "src/h/config.h", we can guarantee that ROUNDS_TO_0 is
> defined with the following preprocessor directives:
>
> #ifndef ROUNDS_TO_0
> #if ( 5 / (-3) == -1 ) && ( (-5) / 3 == -1 ) && ( (-5) / (-3) == 1 )
> #define ROUNDS_TO_0 1
> #else
> #define ROUNDS_TO_0 0
> #endif
> #endif /* ROUNDS_TO_0 */
>
> If there is some platform for which this does not set ROUNDS_TO_0 to the
> appropriate value, you can set it in 'src/h/define.h'.
Well, let's see.
If the #if does not evaluate to true, then the implementation for that
very reason does not truncate to 0, so #define ROUNDS_TO_0 0 is correct.
If, OTOH, it does evaluate to true, then the requirement, in both the
C89 and the C99 Standard, that (a/b)*b + a%b == a, demands that the
modulo operator behaves as expected for platforms that truncate to 0,
and #define ROUNDS_TO_0 1 is correct.
So whether the implementation does truncate towards zero or not, this
snippet is correct.
BTW, strictly speaking this is truncation, not rounding, but that's a
matter of terminology. A newbie like me certainly shouldn't dictate what
the Icon dev team calls things <g>.
Richard